﻿Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraEditors

Public Class Form3

    Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'PcvgppDataSet.khachhang' table. You can move, or remove it, as needed.
        Me.KhachhangTableAdapter.Fill(Me.PcvgppDataSet.khachhang)
        'TODO: This line of code loads data into the 'PcvgppDataSet.nhapchitiet' table. You can move, or remove it, as needed.
        Me.NhapchitietTableAdapter.Fill(Me.PcvgppDataSet.nhapchitiet)
        'TODO: This line of code loads data into the 'PcvgppDataSet.hanghoa_donvitinh' table. You can move, or remove it, as needed.

        Me.Hanghoa_donvitinhTableAdapter.Fill(Me.PcvgppDataSet.hanghoa_donvitinh)
        'TODO: This line of code loads data into the 'PcvgppDataSet.hanghoa' table. You can move, or remove it, as needed.
        Me.HanghoaTableAdapter.Fill(Me.PcvgppDataSet.hanghoa)
        Me.GridView1.OptionsBehavior.Editable = True
        Me.GridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom
    End Sub

    Private Sub GridView1_InvalidRowException(sender As Object, e As DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs) Handles GridView1.InvalidRowException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction
    End Sub

    Private Sub GridView1_InvalidValueException(sender As Object, e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles GridView1.InvalidValueException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.DisplayError
    End Sub

    Private Sub GridView1_ShownEditor(sender As Object, e As System.EventArgs) Handles GridView1.ShownEditor
        Dim view As ColumnView = CType(sender, ColumnView)
        view.ActiveEditor.IsModified = True
    End Sub

    Private Sub GridView1_ValidatingEditor(sender As Object, e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles GridView1.ValidatingEditor
        Dim View As GridView = sender
        If View.FocusedColumn.FieldName = "ten" Then
            'If e.Value Is DBNull.Value Then
            If IsDBNull(e.Value) Then
                e.ErrorText = "không đc rỗng nha cha nội !!!"
                e.Valid = False
            ElseIf e.Value.ToString = "" Then
                e.ErrorText = "không đc rỗng nha ba` nội !!!"
                e.Valid = False
            End If
        End If
    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1View_BeforeLeaveRow(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowAllowEventArgs) Handles RepositoryItemSearchLookUpEdit1View.BeforeLeaveRow

    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1View_RowCellClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs) Handles RepositoryItemSearchLookUpEdit1View.RowCellClick
        Try
            MessageBox.Show(Me.RepositoryItemSearchLookUpEdit1View.GetFocusedRowCellValue("ten").ToString)
        Catch ex As Exception

        End Try

    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1_EditValueChanged(sender As Object, e As System.EventArgs) Handles RepositoryItemSearchLookUpEdit1.EditValueChanged


    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1_EditValueChanging(sender As Object, e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit1.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        'GridView1.SetFocusedRowCellValue("Int", editor.Properties.View.GetRowCellValue(rowHandle, "Int"))
        'GridView1.SetFocusedRowCellValue("Date", editor.Properties.View.GetRowCellValue(rowHandle, "Date"))
        GridView1.SetFocusedRowCellValue("ten", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
        'GridView1.SetFocusedRowCellValue("Date", editor.Properties.View.GetRowCellValue(rowHandle, "Date"))
    End Sub
End Class